Module SimpleEffects
    Private Function DuplicateImage(pixels(,) as color) as color(,)
        dim result(-1, -1) as color
        redim result(ubound( pixels, 1), ubound( pixels, 2 ))
        
    	for x as integer = 0 to ubound( pixels, 1 )
    		for y as integer = 0 to ubound( pixels, 2 )
    		    result(x, y) = pixels(x, y)
    		next
    	next
    	
    	return result
    End Function
    
    Global Function Deg2Rad(degrees as double) as double
        return 3.14159 / 180 * degrees
    End Function
    
    Sub Rotate(pixels(,) as color, angle as double)
        dim sourceImg(-1, -1) as color = duplicateImage( pixels )
        dim width as integer = ubound( pixels, 1 )
        dim height as integer = ubound( pixels, 2 )
        
        angle = angle - deg2Rad(90)
        dim sinVal as double = sin( angle )
        dim cosVal as double = cos( angle )
        
 		for x as integer = 0 to width
			for y as integer = 0 to height
			    dim bs as double = x - width / 2
			    dim cs as double = y - height / 2
			    
			    dim sourceX as integer = bs * sinVal + cs * cosVal + width / 2
				dim sourceY as integer = bs * cosVal - cs * sinVal + height / 2
				
				if sourceX <= width and sourceX >= 0 and sourceY >= 0 and sourceY <= height then
    				pixels( x, y ) = sourceImg( sourceX, sourceY )
    			else
    			    pixels( x, y ) = rgb( 255, 255, 255 )
			    end if
			next
		next
    End Sub
    
	Sub Grayscale(pixels(,) as color)
		for x as integer = 0 to ubound( pixels, 1 )
			for y as integer = 0 to ubound( pixels, 2 )
				dim pixel as color = pixels( x, y )
				dim avg as integer = ( pixel.red + pixel.green + pixel.blue ) / 3
				pixels( x, y ) = rgb( avg, avg, avg )
			next
		next
	End Sub
End Module

grayscale(getPixels)
rotate(getPixels(), deg2rad(90))